/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package algoritmo;


public class IterativeDeepeningAStar extends AStar {

    private int threshold;
    private int maxIter;
    private int costoMin = -1;

    public IterativeDeepeningAStar(Heuristic heur, int maxIter) {
        super(heur);
        this.maxIter = maxIter;
    }

    @Override
    public Node search() {
        threshold = h(start);
        int i = 0;
        while (result == null) {
            costoMin = -1;
            result = super.search();
            threshold = costoMin;        
            i++;
            if (i > maxIter) {
                break;
            }
        }
        return result;
    }

    @Override
    public boolean shouldExpand(Node n) {
        int costo = n.getPathCost() + h(n);
        if (costo > threshold && (costo < costoMin || costoMin == -1)) {
            costoMin = costo;
        }
        return costo <= threshold;
    }

   
}
